﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NFLDriver;

namespace WinFormUI
{
    class Comm
    {
        ServiceReference1.MyWCFServiceClient wcfClient = new ServiceReference1.MyWCFServiceClient();
        ServiceReference1.serviceTeam sTeam = new ServiceReference1.serviceTeam();
        ServiceReference1.serviceUser sUser = new ServiceReference1.serviceUser();

        public Comm()
        {

        }
        public Team getTeam(int index)
        {
            Team tempTeam = new Team();
            ServiceReference1.serviceTeam tempSerTeam;
            tempSerTeam = wcfClient.getServiceTeam(index);
            tempTeam.teamName = tempSerTeam.teamName;
            //String tempGuidString = tempSerTeam.teamId;
            //Guid tempGuid = Guid.Parse(tempGuidString);
            //tempTeam.teamId = tempGuid;
            tempTeam.teamColumn = tempSerTeam.columnNumber;
            tempTeam.setScore(0, tempSerTeam.winLossCode0);
            tempTeam.setScore(1, tempSerTeam.winLossCode1);
            tempTeam.setScore(2, tempSerTeam.winLossCode2);
            tempTeam.setScore(3, tempSerTeam.winLossCode3);
            tempTeam.setScore(4, tempSerTeam.winLossCode4);
            tempTeam.setScore(5, tempSerTeam.winLossCode5);
            tempTeam.setScore(6, tempSerTeam.winLossCode6);
            tempTeam.setScore(7, tempSerTeam.winLossCode7);
            tempTeam.setScore(8, tempSerTeam.winLossCode8);
            tempTeam.setScore(9, tempSerTeam.winLossCode9);
            tempTeam.setScore(10, tempSerTeam.winLossCode10);
            tempTeam.setScore(11, tempSerTeam.winLossCode11);
            tempTeam.setScore(12, tempSerTeam.winLossCode12);
            tempTeam.setScore(13, tempSerTeam.winLossCode13);
            tempTeam.setScore(14, tempSerTeam.winLossCode14);
            tempTeam.setScore(15, tempSerTeam.winLossCode15);
            tempTeam.setScore(16, tempSerTeam.winLossCode16);

            return tempTeam;
        }

        public void createUserAccount(User user)
        {
            ServiceReference1.serviceUser tempSerUser = new ServiceReference1.serviceUser();
            tempSerUser.FirstName = user.FirstName;
            tempSerUser.LastName = user.LastName;
            tempSerUser.Email = user.Email;
            tempSerUser.Password = user.Password;
            //wcfClient.login(tempSerUser);
        }

        public User userLogin(User user)
        {
            ServiceReference1.serviceUser tempSerUser = new ServiceReference1.serviceUser();
            ServiceReference1.serviceUser returnUser;
            User tempUser = new User();

            tempSerUser.Email = user.Email;
            tempSerUser.Password = user.Password;
            tempSerUser.FirstName = "Guest";
            tempSerUser.LastName = "User";
            returnUser = wcfClient.login(tempSerUser);

            tempUser.FirstName = returnUser.FirstName;
            tempUser.LastName = returnUser.LastName;
            tempUser.Email = returnUser.Email;
            tempUser.Password = returnUser.Password;
            if (returnUser.loggedIn)
            {
                tempUser.setLogIn(1);
            }
            for (int i = 0; i < 7; i++)
            {
                tempUser.setSelectedTeam(i, new Team());
            }
            tempUser.getSelectedTeam(0).teamName = returnUser.SelectedTeam0Name;
            tempUser.getSelectedTeam(1).teamName = returnUser.SelectedTeam1Name;
            tempUser.getSelectedTeam(2).teamName = returnUser.SelectedTeam2Name;
            tempUser.getSelectedTeam(3).teamName = returnUser.SelectedTeam3Name;
            tempUser.getSelectedTeam(4).teamName = returnUser.SelectedTeam4Name;
            tempUser.getSelectedTeam(5).teamName = returnUser.SelectedTeam5Name;
            tempUser.getSelectedTeam(6).teamName = returnUser.SelectedTeam6Name;

            return tempUser;

        }

        public void updateUserSelectedTeams(User user)
        {
            ServiceReference1.serviceUser tempSerUser = new ServiceReference1.serviceUser();
            tempSerUser.Email = user.Email;
            tempSerUser.Password = user.Password;
            tempSerUser.SelectedTeam0Name = user.getSelectedTeam(0).teamName;
            tempSerUser.SelectedTeam1Name = user.getSelectedTeam(1).teamName; ;
            tempSerUser.SelectedTeam2Name = user.getSelectedTeam(2).teamName; ;
            tempSerUser.SelectedTeam3Name = user.getSelectedTeam(3).teamName; ;
            tempSerUser.SelectedTeam4Name = user.getSelectedTeam(4).teamName; ;
            tempSerUser.SelectedTeam5Name = user.getSelectedTeam(5).teamName; ;
            tempSerUser.SelectedTeam6Name = user.getSelectedTeam(6).teamName; ;

        }

    }
}
